\documentclass[a4paper,10pt]{article}
\usepackage{fullpage}
\usepackage[british]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
%\usepackage{amsthm} \newtheorem{theorem}{Theorem}
\usepackage{color}
\usepackage{float}

\usepackage{caption}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white}

\usepackage{alltt}
\usepackage{listings}
 \usepackage{aeguill}
\usepackage{dsfont}
%\usepackage{algorithm}
\usepackage[noend]{algorithm2e}
%\usepackage{algorithmicx}
\usepackage{subfig}
\lstset{% parameters for all code listings
language=Python,
frame=single,
basicstyle=\small, % nothing smaller than \footnotesize, please
tabsize=2,
numbers=left,
% framexleftmargin=2em, % extend frame to include line numbers
%xrightmargin=2em, % extra space to fit 79 characters
breaklines=true,
breakatwhitespace=true,
prebreak={/},
captionpos=b,
columns=fullflexible,
escapeinside={\#*}{\^^M}
}


% Alter some LaTeX defaults for better treatment of figures:
    % See p.105 of "TeX Unbound" for suggested values.
    % See pp. 199-200 of Lamport's "LaTeX" book for details.
    % General parameters, for ALL pages:
    \renewcommand{\topfraction}{0.9}	% max fraction of floats at top
    \renewcommand{\bottomfraction}{0.8}	% max fraction of floats at bottom
    % Parameters for TEXT pages (not float pages):
    \setcounter{topnumber}{2}
    \setcounter{bottomnumber}{2}
    \setcounter{totalnumber}{4} % 2 may work better
    \setcounter{dbltopnumber}{2} % for 2-column pages
    \renewcommand{\dbltopfraction}{0.9}	% fit big float above 2-col. text
    \renewcommand{\textfraction}{0.07}	% allow minimal text w. figs
    % Parameters for FLOAT pages (not text pages):
    \renewcommand{\floatpagefraction}{0.7}	% require fuller float pages
% N.B.: floatpagefraction MUST be less than topfraction !!
    \renewcommand{\dblfloatpagefraction}{0.7}	% require fuller float pages

% remember to use [htp] or [htpb] for placement


\usepackage{fancyvrb}
%\DefineVerbatimEnvironment{code}{Verbatim}{fontsize=\small}
%\DefineVerbatimEnvironment{example}{Verbatim}{fontsize=\small}

\newcommand{\keywords}[1]{\par\addvspace\baselineskip
\noindent\keywordname\enspace\ignorespaces#1}


\usepackage{tikz} \usetikzlibrary{trees}
\usepackage{hyperref} % should always be the last package

% useful colours (use sparingly!):
\newcommand{\blue}[1]{{\color{blue}#1}}
\newcommand{\green}[1]{{\color{green}#1}}
\newcommand{\red}[1]{{\color{red}#1}}

% useful wrappers for algorithmic/Python notation:
\newcommand{\length}[1]{\text{len}(#1)}
\newcommand{\twodots}{\mathinner{\ldotp\ldotp}} % taken from clrscode3e.sty
\newcommand{\Oh}[1]{\mathcal{O}\left(#1\right)}

% useful (wrappers for) math symbols:
\newcommand{\Cardinality}[1]{\left\lvert#1\right\rvert}
%\newcommand{\Cardinality}[1]{\##1}
\newcommand{\Ceiling}[1]{\left\lceil#1\right\rceil}
\newcommand{\Floor}[1]{\left\lfloor#1\right\rfloor}
\newcommand{\Iff}{\Leftrightarrow}
\newcommand{\Implies}{\Rightarrow}
\newcommand{\Intersect}{\cap}
\newcommand{\Sequence}[1]{\left[#1\right]}
\newcommand{\Set}[1]{\left\{#1\right\}}
\newcommand{\SetComp}[2]{\Set{#1\SuchThat#2}}
\newcommand{\SuchThat}{\mid}
\newcommand{\Tuple}[1]{\langle#1\rangle}
\newcommand{\Union}{\cup}
\usetikzlibrary{positioning,shapes,shadows,arrows}

\usepackage{url}


\pagestyle{empty}

\title{Distributed Systems - Spring 2013 \\ Milestone 2 Report}

\author{Group 2}

\begin{document}

\maketitle

\tableofcontents

\section{Work done}

During the Milestone 2 week the following work has been done:

\begin{itemize}
	\item Chosen to use LeJOS for the robot.
	\item Written a simple Java server and robot program that allows us to move the robot.
	\item Made initial design plans for the server, client and robot.
	\item Contacted the other groups to set up a meeting about the communication between server-robot and server-client.
	\item Made a simple protocol to be used by all the groups. It is a simple XML document, and it is expandable by each group individually.
\end{itemize}

\subsection{Operating system}
\label{sec:os}

The group had decided from the previous meeting to use either BrickOS (C/C++) or LeJOS (Java) for the robot. This week the group did some testing on both the operating systems to decide which operating system to use. The testing resulted in the following conclusions:


\paragraph{ LeJOS}
	\begin{itemize}
		\item Pros
		\begin{itemize}
			\item There are many previous Mindstorms project using LeJOS on GitHub that can be used for inspiration.
			\item The use of Java allows the group to write code in a high-level language.
			\item LeJOS has very good documentation and there is a lot of easy-to-find information about it.
			\item Simulators available.
		\end{itemize}
		\item Cons
		\begin{itemize}
			\item The use of Java requires a Virtual Machine on the NXT unit, which will require some extra memory.
		\end{itemize}
	\end{itemize}
\paragraph{BrickOS}
	\begin{itemize}
		\item Pros
		\begin{itemize}
			\item Since BrickOS uses C/C++, no Virtual Machine is needed. This allows us to use all available memory for our own code.
		\end{itemize}
		\item Cons
		\begin{itemize}
			\item There are very few previous projects using BrickOS available as references or inspiration.
			\item The programming languages used with BrickOS are much lower level. This might make the development of the robot more extensive, taking time from other parts of the project.
		\end{itemize}
	\end{itemize}

\paragraph{Summary} The Pro's of the LeJOS are far better than those of BrickOS. The only reason we could see not to use it would be if the Virtual Machine would need an unacceptably large amount of memory. User lawrie, who is a LeJOS Team Member, anounced on the LeJOS Forum that the Virtual Machine requires around 14 Kb of RAM, leaving around 50 for our own program. This was judged to be enough memory for our needs, and that together with the availability of good documentation and previous projects led to the decision to use LeJOS.

\subsection{Simple server and robot program}

The group has written a simple Java Bluetooth solution for use on the server and robot. To communicate with the robot, a intergroup meeting was held were a common protocol was agreed on.

The protocol is a XML structure that in it's most basic form must have 4 commands that all groups need to support; move, rotate, scan and reboot. All communications to the robot are acknowledged by a return message that contains the data sent to the robot, and the responses to that message. Only the messages that are relevant for the current communication needs to be sent, that means, if you want to move, you do not have to send a "rotate 0 degrees" command.

The protocol can be expanded by each group by adding own commands to it. The new commands must have names in the form \emph{GXname}, where X is the group number and name is the name of the command.

Group 2 has added the command G2close which is used to signal the robot that the connection will be broken.

If the connection is lost between the robot and the server, the robot waits for a new connection in the current position. The robot will not do anything active to regain contact with the server. This will be changed in the forthcoming development.

The protocol looks like this:

\subsection{Server-to-robot protocol}

\begin{lstlisting}[language=XML]
<?xml version="1.0" encoding="utf-8"?>
<s2r>
	<move req=""/>
	<rotate req=""/>
	<scan n=""/>
	<reboot/>
	<G2close/>
</s2r>
\end{lstlisting}

\[
\begin{tabular}{c |c | l}
Command & Parameters & Description \\
\hline
move & req & Moves the robot \emph{req} cm. Positive values move the robot forward,\\ 
&& negative backward. \\
rotate & req & Rotates the robot \emph{req} degrees. Positive values moves the robot \\
&& clockwise, negative counter clockwise. \\
scan & n & Makes the robot use the US sensor to measure distance in \emph{n} directions,\\
&& the angle between every direction being the same. \\
reboot & N/A & Reboots the robot. \\
G2close & N/A & Initializes bluetooth connection termination. \\
\end{tabular}
\]

\subsection{Robot-to-server protocol}


\begin{lstlisting}[language=XML]
<?xml version="1.0" encoding="utf-8"?>
<s2r>
	<move req="" real=""/>
	<rotate req="" real=""/>
	<scan n="" n1="" n2="" n3="" (...) nN=""/>
	<reboot/>
	<G2close/>
</s2r>
\end{lstlisting}

\[
\begin{tabular}{c |c | l}
Command & Parameters & Description \\
\hline
move & req, real & Acknowledges the request to move \emph{req} cm, and reports \\
&& the actual movement to be \emph{real} cm. \\
rotate & req, real & Acknowledges the request to rotate \emph{req} degrees, and \\
&& reports the actual movement to be \emph{real} degrees. \\
scan & n, n1, n2, n3, ... nN & Acknowledges the request to measure in \emph{n} directions, \\
&& and returns all the \emph{nN} points. \\
reboot & N/A & Acknowledges reboot command recieved. \\
G2close & N/A & Acknowledges connection termination command\\
&& recieved. \\
\end{tabular}
\]

\subsection{Design plans}

The group has made UML diagrams for the client, server and robot. While the communication interfaces are not yet finished, it gives an overview of the internal workings of each part of the distributed system.

\subsubsection{Server design}

The server will handle the calculations needed to move the robot in either the map that the robot has constructed, or my manual control. It will communicate with multiple robots at one time. The ServerInterface will be defined when we have talked to the other groups of how to implement the communication protocols.

A UML diagram of the Server design can be seen in Figure \ref{fig:server}.

\begin{figure}[p]
\includegraphics[width=\textwidth] {bilder/group2_server_uml.png}
\caption{UML diagram of the Server design.}
\label{fig:server}
\end{figure}

\subsubsection{Robot design}

The robot in our design relies heavily on the server for data processing and instructions. The robot in itself only has the processing power to generate the data which is then sent to the server. It can also recieve the commands associated with the analyzed data.

A UML diagram of the Robot design can be seen in Figure \ref{fig:robot}.

\begin{figure}[p]
\includegraphics[width=\textwidth] {bilder/Robot_diagram.png}
\caption{UML diagram of the Robot design.}
\label{fig:robot}
\end{figure}

\subsubsection{Client design}

A UML diagram of the Client design can be seen in Figure \ref{fig:client}.

\begin{figure}[p]
\includegraphics[width=\textwidth] {bilder/clientUML.png}
\caption{UML diagram of the Client design.}
\label{fig:client}
\end{figure}

\section{Decisions}

The group has made a few decisions that will affect the future work.

\begin{itemize}
	\item The group decided to use LeJOS for the robot over BrickOS, see section \ref{sec:os}.
	\item Since the server shall be able to handle communications with the robots and clients of the other groups, the earlier design where the Raspberry Pi server was tightly integrated with the robot has to be trashed. The group might still use the Raspberry Pi, but it shall not be integrated with the robot. 
	\item The group has decided together with the other groups to use a expandable XML protocol for communication between server and robot. All groups must support the basic functionality of the protocol.
	\item The UML diagram for the robot has been accepted.
\end{itemize}

\section{Notes from the Milestone meeting}

The group needs to get better at reporting progress. This includes:

\begin{itemize}
	\item Upload design plans and changes to them to Redmine.
	\item Report time spent.
	\item Update the individual weekly progress reports.
\end{itemize}

\section{Work to be done}


\begin{itemize}
	\item Refactor robot code to give better abstraction layers.
	\item Comment robot code.
	\item Make final changes and accept UML diagram of Server.
	\item Implement server.
	\item Start designing client interface.
	\item Specify how the robot will know it's current position.
	\item Specify how the robot explores the environment.
	\item Update the Gantt chart on the Redmine server to reflect our deadlines.
\end{itemize}


\end{document}